#include <iostream>

#include "Image.H"
#include "Util.H"
#include "IO.H"
#include "dynamicProgamming.h"


using namespace std;
using namespace pip;

int main(int argc, char *argv[])
{
	if (argc < 1) {    //get input
	  error("", "Usage: dynamicprogram -i [input.pip] -n [int] -o [output.pip]  -m [0 | 1] \n");
	  return 1;
	}
	vector<string> args(argv, argv + argc);

	Image<float> in_float;
	Image<short> in_short;  
	Image<unsigned char> in_char;
	Image<float> output;

	string inputname("");
	string outputname("dp_segmented.pip");

	int n(3);
	bool max(false);

	getScalarArg(args, "-i", inputname); 
	getScalarArg(args, "-o", outputname); 
	getScalarArg(args, "-m", max);
	getScalarArg(args, "-n", n);

	if(max)
		cout << "max" << endl;
	else if(!max)
		cout << "min" << endl;

	if(!(n%2) || n < 1) 
	{
		error("", "Usage: only odd 'n' allowed, above 0!");
	}
	
	if (importFile(in_float, inputname)) // call 'connect' function with correct args
	{
		DynamicPath(in_float,n,max);
		if (!exportFile(in_float, outputname))
		{
			error("", "Cannot save result onto disk...");
		}
		exportFile(convertAllToUnsignedChar(output),"result.bmp");
	} else if (importFile(in_short, inputname)) 
	{
		DynamicPath(in_short,n,max);
		if (!exportFile(in_short, outputname))
		{
			error("", "Cannot save result onto disk...");
		}
		exportFile(convertAllToUnsignedChar(in_short),"result.bmp");
	} else if (importFile(in_char, inputname)) 
	{
		cout<<"good\n"<<endl;
		DynamicPath(in_char,n,max);
		if (!exportFile(in_char, outputname))
		{
			error("", "Cannot save result onto disk...");
		}
		exportFile(in_char,"eye_.bmp");
	} else 
	{   
		cout << "The inputimage is not an Image of pixeltype: [unsigned char, short or float] !\n";
		return 4;
	}

	
	
	

	//system("pause");
	return 0;
}
